/*************************
* SQUARE STAND
*************************/
function Stand(){
	
	var size = 100;
	var quicktigame2d = require('com.googlecode.quicktigame2d');
	var offset = (Titanium.Platform.displayCaps.platformWidth - size)/2;
	
	var self = quicktigame2d.createMapSprite({
		image: "images/squares.png",
        tileWidth: 10,
        tileHeight: 10,
        border: 0,
        margin: 0,
        y: 0,
        x: offset,
        width: 100,
		height: 100
	});
	self.firstgid = 1;
	
	var curLevel = Titanium.App.Properties.getInt("currentLevel", 1);
	var LevelLoader = require('ui/LevelLoader');
	self.tiles = new LevelLoader(curLevel);
	
	this.getSprite = function(){
		return self;
	};
	
	//stand is moving to left
	this.left = true;
	
	var speed = 5;
	var time = 5;
	var mode = 1;
	var maxSpeed = 10;
	var rightSide = Titanium.Platform.displayCaps.platformWidth - size;
	
	var moveStand = function(move){
		self.x += move;
	};
	
	this.step = function(){
		//mode
		if(time==0)
		{
			time = Math.floor(Math.random()*6)+1;
			mode = Math.floor(Math.random()*3);
		}
		//mode 1 doesn't do anything
		if(mode ==0)
		{
			if(speed < maxSpeed)
			{
				speed++;
			}
		}
		else if(mode == 2)
		{
			if(speed>0)
			{
				speed--;
			}
		}
		time--;
		if(this.left)
		{
			if(self.x <= 0)
			{
				this.left = false;
			}
			else
			{
				moveStand(-speed);
			}
		}
		else
		{
			if(self.x >= rightSide)
			{
				this.left = true;
			}
			else
			{
				moveStand(speed);
			}
		}
	};
};

module.exports = Stand;